package com.suray.wcs.service.core.util;


import com.suray.basic.wcs.utils.IBaseEnum;
import com.suray.wcs.service.pojo.BaseEum;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 用于返回前台下拉框中的枚举对象
 *
 * @author zhr
 */
public class ReturnTypeBox {
    public static List<BaseEum> returnTypeBox(Class<?> e) {
        try {
            List<BaseEum> baseEunmList = new ArrayList<BaseEum>();
            IBaseEnum<?>[] enumConstants = (IBaseEnum[]) e.getEnumConstants();
            for (IBaseEnum<?> eVal : enumConstants) {
                baseEunmList.add(new BaseEum(eVal.getVal(), eVal.getDescription()));
            }
            return baseEunmList;
        } catch (Exception ex) {
            System.err.println(ex.getMessage());
            System.err.println("枚举类型错误,请继承IBaseEnum");
            return Collections.emptyList();
        }
    }
}
